package cn.wolfcode.wolf.article.controller;

import cn.wolfcode.wolf.article.domain.Destination;
import cn.wolfcode.wolf.article.domain.Region;
import cn.wolfcode.wolf.article.domain.Region;
import cn.wolfcode.wolf.article.service.DestinationService;
import cn.wolfcode.wolf.article.service.RegionService;
import cn.wolfcode.wolf.auth.anno.RequireLogin;
import cn.wolfcode.wolf.core.utils.Result;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/regions")
public class RegionController {
    private final RegionService regionService;
    private final DestinationService destinationService;
    public RegionController(RegionService regionService, DestinationService destinationService) {
        this.regionService = regionService;
        this.destinationService = destinationService;
    }
    @GetMapping
    public Result<Page<Region>> pageList(Page<Region> page){
        return Result.success(regionService.page(page));
    }
    @GetMapping("/hotList")
    public Result<List<Region>> hostList(){
        return Result.success(regionService.findHotList());
    }

    @PostMapping("/save")
    public Result<?> save(Region region){
        regionService.save(region);
        return Result.success(Result.SUCCESS_MESSAGE);
    }

    @PostMapping("/update")
    public Result<?> updateById( Region region){
        regionService.updateById(region);
        return Result.success(Result.SUCCESS_MESSAGE);
    }
    @PostMapping("/delete/{id}")
    public Result<?> deleteById(@PathVariable Long id){
        regionService.removeById(id);
        return Result.success(Result.SUCCESS_MESSAGE);
    }
    @GetMapping("/detail")
    public Result<Region> getById(Long id){
        return Result.success(regionService.getById(id));
    }
    @GetMapping("/{id}/destination")
    public Result<List<Destination>> getDestinationByRegionId(@PathVariable Long id){
        List<Destination> list = destinationService.getDestinationByRegionId(id);
        return Result.success(list);
    }
}
